<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
      <el-form-item label="项目年度" prop="projectA">
        <el-input
          v-model="queryParams.projectA"
          placeholder="请输入项目年度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectB">
        <el-input
          v-model="queryParams.projectB"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目投资方" prop="projectC">
        <el-input
          v-model="queryParams.projectC"
          placeholder="请输入项目投资方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="责任单位" prop="projectD">
        <el-input
          v-model="queryParams.projectD"
          placeholder="请输入责任单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="相关责任单位" prop="projectE">
        <el-input
          v-model="queryParams.projectE"
          placeholder="请输入相关责任单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区领导" prop="projectF">
        <el-input
          v-model="queryParams.projectF"
          placeholder="请输入区领导"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目类别" prop="projectG">
        <el-input
          v-model="queryParams.projectG"
          placeholder="请输入项目类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目当期阶段" prop="projectH">
        <el-input
          v-model="queryParams.projectH"
          placeholder="请输入项目当期阶段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产业领域-大类" prop="projectI">
        <el-input
          v-model="queryParams.projectI"
          placeholder="请输入产业领域-大类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产业领域-小类" prop="projectJ">
        <el-input
          v-model="queryParams.projectJ"
          placeholder="请输入产业领域-小类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行业类别" prop="projectK">
        <el-input
          v-model="queryParams.projectK"
          placeholder="请输入行业类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目总投资查询" prop="projectL">
        <el-input
          v-model="queryParams.projectL"
          placeholder="请输入项目总投资查询"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资金区间起" prop="projectM">
        <el-input
          v-model="queryParams.projectM"
          placeholder="请输入资金区间起"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资金区间止" prop="projectN">
        <el-input
          v-model="queryParams.projectN"
          placeholder="请输入资金区间止"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投资类别" prop="projectO">
        <el-input
          v-model="queryParams.projectO"
          placeholder="请输入投资类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="附件" prop="projectP">
        <el-input
          v-model="queryParams.projectP"
          placeholder="请输入附件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否督办" prop="projectQ">
        <el-input
          v-model="queryParams.projectQ"
          placeholder="请输入是否督办"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否调度" prop="projectR">
        <el-input
          v-model="queryParams.projectR"
          placeholder="请输入是否调度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目审核状态" prop="projectT">
        <el-input
          v-model="queryParams.projectT"
          placeholder="请输入项目审核状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目进度状态" prop="projectU">
        <el-input
          v-model="queryParams.projectU"
          placeholder="请输入项目进度状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否区领导关注项目" prop="projectV">
        <el-input
          v-model="queryParams.projectV"
          placeholder="请输入是否区领导关注项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否专报项目" prop="projectW">
        <el-input
          v-model="queryParams.projectW"
          placeholder="请输入是否专报项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调度专报项目" prop="projectX">
        <el-input
          v-model="queryParams.projectX"
          placeholder="请输入调度专报项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期">
        <el-date-picker
          v-model="daterangeProjectAc"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:zaitan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:zaitan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:zaitan:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:zaitan:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="zaitanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="项目年度" align="center" prop="projectA" />
      <el-table-column label="项目名称" align="center" prop="projectB" />
      <el-table-column label="项目投资方" align="center" prop="projectC" />
      <el-table-column label="责任单位" align="center" prop="projectD" />
      <el-table-column label="相关责任单位" align="center" prop="projectE" />
      <el-table-column label="区领导" align="center" prop="projectF" />
      <el-table-column label="项目类别" align="center" prop="projectG" />
      <el-table-column label="项目当期阶段" align="center" prop="projectH" />
      <el-table-column label="产业领域-大类" align="center" prop="projectI" />
      <el-table-column label="产业领域-小类" align="center" prop="projectJ" />
      <el-table-column label="行业类别" align="center" prop="projectK" />
      <el-table-column label="项目总投资查询" align="center" prop="projectL" />
      <el-table-column label="资金区间起" align="center" prop="projectM" />
      <el-table-column label="资金区间止" align="center" prop="projectN" />
      <el-table-column label="投资类别" align="center" prop="projectO" />
      <el-table-column label="附件" align="center" prop="projectP" />
      <el-table-column label="是否督办" align="center" prop="projectQ" />
      <el-table-column label="是否调度" align="center" prop="projectR" />
      <el-table-column label="项目审核状态" align="center" prop="projectT" />
      <el-table-column label="项目进度状态" align="center" prop="projectU" />
      <el-table-column label="是否区领导关注项目" align="center" prop="projectV" />
      <el-table-column label="是否专报项目" align="center" prop="projectW" />
      <el-table-column label="调度专报项目" align="center" prop="projectX" />
      <el-table-column label="日期" align="center" prop="projectAc" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.projectAc, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:zaitan:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:zaitan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改在谈项目对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" >
        <el-form-item label="项目年度" prop="projectA">
          <el-input v-model="form.projectA" placeholder="请输入项目年度" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectB">
          <el-input v-model="form.projectB" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目投资方" prop="projectC">
          <el-input v-model="form.projectC" placeholder="请输入项目投资方" />
        </el-form-item>
        <el-form-item label="责任单位" prop="projectD">
          <el-input v-model="form.projectD" placeholder="请输入责任单位" />
        </el-form-item>
        <el-form-item label="相关责任单位" prop="projectE">
          <el-input v-model="form.projectE" placeholder="请输入相关责任单位" />
        </el-form-item>
        <el-form-item label="区领导" prop="projectF">
          <el-input v-model="form.projectF" placeholder="请输入区领导" />
        </el-form-item>
        <el-form-item label="项目类别" prop="projectG">
          <el-input v-model="form.projectG" placeholder="请输入项目类别" />
        </el-form-item>
        <el-form-item label="项目当期阶段" prop="projectH">
          <el-input v-model="form.projectH" placeholder="请输入项目当期阶段" />
        </el-form-item>
        <el-form-item label="产业领域-大类" prop="projectI">
          <el-input v-model="form.projectI" placeholder="请输入产业领域-大类" />
        </el-form-item>
        <el-form-item label="产业领域-小类" prop="projectJ">
          <el-input v-model="form.projectJ" placeholder="请输入产业领域-小类" />
        </el-form-item>
        <el-form-item label="行业类别" prop="projectK">
          <el-input v-model="form.projectK" placeholder="请输入行业类别" />
        </el-form-item>
        <el-form-item label="项目总投资查询" prop="projectL">
          <el-input v-model="form.projectL" placeholder="请输入项目总投资查询" />
        </el-form-item>
        <el-form-item label="资金区间起" prop="projectM">
          <el-input v-model="form.projectM" placeholder="请输入资金区间起" />
        </el-form-item>
        <el-form-item label="资金区间止" prop="projectN">
          <el-input v-model="form.projectN" placeholder="请输入资金区间止" />
        </el-form-item>
        <el-form-item label="投资类别" prop="projectO">
          <el-input v-model="form.projectO" placeholder="请输入投资类别" />
        </el-form-item>
        <el-form-item label="附件" prop="projectP">
          <el-input v-model="form.projectP" placeholder="请输入附件" />
        </el-form-item>
        <el-form-item label="是否督办" prop="projectQ">
          <el-input v-model="form.projectQ" placeholder="请输入是否督办" />
        </el-form-item>
        <el-form-item label="是否调度" prop="projectR">
          <el-input v-model="form.projectR" placeholder="请输入是否调度" />
        </el-form-item>
        <el-form-item label="项目审核状态" prop="projectT">
          <el-input v-model="form.projectT" placeholder="请输入项目审核状态" />
        </el-form-item>
        <el-form-item label="项目进度状态" prop="projectU">
          <el-input v-model="form.projectU" placeholder="请输入项目进度状态" />
        </el-form-item>
        <el-form-item label="是否区领导关注项目" prop="projectV">
          <el-input v-model="form.projectV" placeholder="请输入是否区领导关注项目" />
        </el-form-item>
        <el-form-item label="是否专报项目" prop="projectW">
          <el-input v-model="form.projectW" placeholder="请输入是否专报项目" />
        </el-form-item>
        <el-form-item label="调度专报项目" prop="projectX">
          <el-input v-model="form.projectX" placeholder="请输入调度专报项目" />
        </el-form-item>
        <el-form-item label="日期" prop="projectAc">
          <el-date-picker clearable
            v-model="form.projectAc"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZaitan, getZaitan, delZaitan, addZaitan, updateZaitan } from "@/api/system/zaitan";

export default {
  name: "Zaitan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 在谈项目表格数据
      zaitanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期时间范围
      daterangeProjectAc: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectA: null,
        projectB: null,
        projectC: null,
        projectD: null,
        projectE: null,
        projectF: null,
        projectG: null,
        projectH: null,
        projectI: null,
        projectJ: null,
        projectK: null,
        projectL: null,
        projectM: null,
        projectN: null,
        projectO: null,
        projectP: null,
        projectQ: null,
        projectR: null,
        projectT: null,
        projectU: null,
        projectV: null,
        projectW: null,
        projectX: null,
        projectAc: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询在谈项目列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeProjectAc && '' != this.daterangeProjectAc) {
        this.queryParams.params["beginProjectAc"] = this.daterangeProjectAc[0];
        this.queryParams.params["endProjectAc"] = this.daterangeProjectAc[1];
      }
      listZaitan(this.queryParams).then(response => {
        this.zaitanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectA: null,
        projectB: null,
        projectC: null,
        projectD: null,
        projectE: null,
        projectF: null,
        projectG: null,
        projectH: null,
        projectI: null,
        projectJ: null,
        projectK: null,
        projectL: null,
        projectM: null,
        projectN: null,
        projectO: null,
        projectP: null,
        projectQ: null,
        projectR: null,
        projectT: null,
        projectU: null,
        projectV: null,
        projectW: null,
        projectX: null,
        projectAc: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeProjectAc = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加在谈项目";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getZaitan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改在谈项目";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateZaitan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZaitan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除在谈项目编号为"' + ids + '"的数据项？').then(function() {
        return delZaitan(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/zaitan/export', {
        ...this.queryParams
      }, `zaitan_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
